/*
 * @Author: zhaojiawei 
 * @Date: 2018-12-05 18:13:37 
 * @Last Modified by: zhaojiawei
 * @Last Modified time: 2018-12-05 21:59:58
 */

import React,{Component} from 'react';
import {
    View,
    Text,
    StyleSheet,
    Navigator,
    WebView,
    TextInput,
    DeviceEventEmitter,
}from 'react-native';
import ViewUtils from '../util/ViewUtils'
import NavigationBar from '../../js/common/NavigationBar';


export default class RepositoryDetail extends Component{
            constructor(props) {
                     super(props);
                     this.url=this.props.item.html_url;
                     let title=this.props.item.full_name;
                     this.state ={
                         url:this.url,
                         title:title,
                         canGoBack:false
                     }   
            }
            // go() {
            //     this.setState({
            //         url:this.text
            //     })
            // }
            onBack() {
                if(this.state.canGoBack){
                      this.webView.goBack();
                }else{
                    this.props.navigator.pop();
                }
            }
            onNavigationStateChange(e) {
                this.setState({
                    canGoBack:e.canGoBack,
                    url:e.url,
                })
            }
            render() {
                return <View style={styles.container}>
                    <NavigationBar
                        title={this.state.title}
                        style={{backgroundColor:'#6495ED'}}
                        leftButton={ViewUtils.getLeftButton(()=>this.onBack())}
                        />
                        <WebView
                            ref={webView=>this.webView=webView}
                            source={{uri:this.state.url}}
                            onNavigationStateChange={(e)=>this.onNavigationStateChange(e)}
                            startInLoadingState={true}
                        />
                    </View>
            }
        }
const styles = StyleSheet.create({
    container:{
        flex:1,
    },
    tips: {
        fontSize: 20,
    },
    row:{
        flexDirection:'row',
        alignItems:'center',
        margin:10,
    },
    input:{
        height:40,
        flex:1,
        borderWidth:1 ,
        margin:2,
    }
})